<?php
class Form_UserProfile extends Zend_Form
{
   /**
    * init() routine called when Zend_Form objects are created.
    * It make sense to define form elements in this method.
    * 
    * @see    http://framework.zend.com/manual/en/zend.form.html
    * @return void
    */ 
    public function init()
    {
         $this->setAction('/user/updateprofile');
                 $this->setMethod('POST');
        
         $this->setElementFilters(array('StringTrim'));
        
         $this->setAttrib('id', 'userProfileForm');
         
         $this->addDecorator('userProfileForm')
              ->addDecorator('HtmlTag', array('tag' => '<ul>'));
         
                                  
         $username = new Zend_Form_Element_Text('openid_identifier');
         $username->setLabel('username')
                  ->setAttrib('class', 'field')
                  ->setAttrib('readonly', 'true')
                  ->setAttrib('onkeyup','checkForRange(this, 4, 100);')
                  ->setAttrib('onclick','checkForRange(this, 4, 100);')
                  ->setDescription('msgUsername')
                  ->addValidator('StringLength', true, array('min' => '4', 'max' => '100'))
                  ->setDecorators(array(
                        array('ViewHelper', array('helper'=>'formText')),
                        array('Label', array('separator'=>' ', 'class'=>'gray labelfield')),
                        array('Errors'),
                        array('Description', array('tag' => 'span', 'class' => 'hint'))
                  ));
                    
         $password = new Zend_Form_Element_Password('password');
         $password->setLabel('Password:')
                  ->setAttrib('class', 'field')
                  ->setAttrib('onkeyup','checkPassword(this);')
                  ->setAttrib('onclick','checkPassword(this);')
                  ->setDescription('msgPassword')
                  ->addValidator(new Form_PasswordConfirmation())
                  ->setDecorators(array(
                        array('ViewHelper'),
                        array('Label', array('separator'=>' ', 'class'=>'gray labelfield')),
                        array('Errors'),
                        array('Description', array('tag' => 'span', 'class' => 'hint'))
                  ));
                    
         $confirmpwd = new Zend_Form_Element_Password('confirmPassword');
         $confirmpwd->setLabel('confirm')
                  ->setAttrib('class', 'field')
                  ->setAttrib('onkeyup','checkPassword(this);')
                  ->setAttrib('onclick','checkPassword(this);')
                  ->setDescription('msgPassword')
                  ->setDecorators(array(
                        array('ViewHelper'),
                        array('Label', array('separator'=>' ', 'class'=>'gray labelfield')),
                        array('Errors'),
                        array('Description', array('tag' => 'span', 'class' => 'hint'))
                  ));

         $nickname = new Zend_Form_Element_Text('nickname');
         $nickname->setLabel('Nickname:')
                  ->setAttrib('class', 'field')
                  ->setAttrib('onkeyup','checkForRange(this, 4, 50);')
                  ->setAttrib('onclick','checkForRange(this, 4, 50);')
                  ->setDescription('msgNickname')
                  ->setRequired(true)
                  ->addValidator('StringLength', true, array('min' => '4', 'max' => '50'))   
                  ->setDecorators(array(
                        array('ViewHelper', array('helper'=>'formText')),
                        array('Label', array('separator'=>' ', 'class'=>'gray labelfield')),
                        array('Errors'),
                        array('Description', array('tag' => 'span', 'class' => 'hint'))
                  ));
         
         $fullname = new Zend_Form_Element_Text('fullname');
         $fullname->setLabel('fullname')
                  ->setAttrib('class', 'field')
                  ->setAttrib('onkeyup','checkForRange(this, 4, 40);')
                  ->setAttrib('onclick','checkForRange(this, 4, 40);')
                  ->setDescription('msgFullname')
                  ->setRequired(true)
                  ->addValidator('StringLength', true, array('min' => '4', 'max' => '40'))
                  ->setDecorators(array(
                        array('ViewHelper', array('helper'=>'formText')),
                        array('Label', array('separator'=>' ', 'class'=>'gray labelfield')),
                        array('Errors'),
                        array('Description', array('tag' => 'span', 'class' => 'hint'))
                  ));

         $email = new Zend_Form_Element_Text('email');
         $email->setLabel('e-mail: ')
               ->setAttrib('class', 'field')
               ->setAttrib('onkeyup','checkEmail(this);')
               ->setAttrib('onclick','checkEmail(this);')
               ->setDescription('msgEmail')
               ->setRequired(true)
               ->addValidator('EmailAddress', true)
               ->setDecorators(array(
                        array('ViewHelper', array('helper'=>'formText')),
                        array('Label', array('separator'=>' ', 'class'=>'gray labelfield')),
                        array('Errors'),
                        array('Description', array('tag' => 'span', 'class' => 'hint'))
               ));            
         
         $language = new Zend_Form_Element_Select('language');
         $language->setLabel('lang')
                  ->setAttrib('class', 'field NoHints')
                  ->setRequired(true)
                  ->setMultiOptions(array(
                    'it_IT'=>'italian', 
                    'en_EN'=>'english',
                    'es_ES'=>'spanish',
                    'fr_FR'=>'french',
                    'de_DE'=>'german'
                  ))
                  ->setDecorators(array(
                        array('ViewHelper'),
                        array('Label', array('separator'=>' ', 'class'=>'gray labelfield')),
                        array('Errors')
                  ));

         $user_oid = new Zend_Form_Element_Hidden('user_oid');
         $user_oid->setDecorators(array('ViewHelper'));
         $profile_oid = new Zend_Form_Element_Hidden('profile_oid');
         $profile_oid->setDecorators(array('ViewHelper'));
         $is_openid = new Zend_Form_Element_Hidden('isOpenID');
         $is_openid->setDecorators(array('ViewHelper'));
         
         // Submit
         $submit = new Zend_Form_Element_Submit('submit');
         $submit->setLabel('save')
                        ->setAttrib('class', 'profileSubmit')
                        ->setDecorators(array(
                            array('ViewHelper')
                        ));
                
         /*Generazione delle Categorie*/                
         $categoryFeedProfile = new Zend_Form_Element_MultiCheckbox('categoryFeedProfile');
         $categoryFeedProfile->setAttrib('class', 'catCheck')
                             ->setRegisterInArrayValidator(false)
                             ->setMultiOptions(array())
	                         ->setDecorators(array(
	                             array('ViewHelper'),
	                             array('Label', array('class' => 'gray')),
	                             array('HtmlTag', array('tag' => 'li', 'class' => 'element-group-category'))
	                         ));
                             

	    
         $this->addElements(array(
                $username,
                $password,
                $confirmpwd,
                $nickname,
                $fullname,
                $email,
                $language,
                $user_oid,
                $profile_oid,
                $is_openid,
                $submit,
                $categoryFeedProfile
         ));
         
         
         $this->setDecorators(array(
                'FormElements',
                'Form',
                array('ViewScript', array('script' => 'userprofile.phtml'))
         ));
          
    }    
}
